#include "pushbutton.h"
GPushButton::GPushButton(QString normalImg, QString pressImg)//构造函数
{
    this->pressPath = pressImg;
    this->normalPath = normalImg;

    //创建Qpixmap
    QPixmap pix;//贴图
    pix.load(this->normalPath);//贴图载入

    //设置按钮固定尺寸
    this->setFixedSize(pix.width(),pix.height());
    //设置不规则样式
    this->setStyleSheet("QPushButton{border:0px;}");//0宽度边框
    //设置图标
    this->setIcon(pix);
    //设置图标大小
    this->setIconSize(QSize(pix.width(),pix.height()));
}
void GPushButton::mousePressEvent(QMouseEvent *event)//按下事件
{
    //按下路径不为空 切图
    if(this->pressPath!="")
    {
        QPixmap pix;
        pix.load(this->pressPath);

        //设置按钮固定尺寸
        this->setFixedSize(pix.width(),pix.height());
        //设置不规则样式
        this->setStyleSheet("QPushButton{border:0px;}");
        //设置图标
        this->setIcon(pix);
        //设置图标大小
        this->setIconSize(QSize(pix.width(),pix.height()));
    }

    //其他事件交给父类处理
    QPushButton::mousePressEvent(event);
}
void GPushButton::mouseReleaseEvent(QMouseEvent *event)//松开事件
{
    if(this->pressPath!="")
    {
        QPixmap pix;
        pix.load(this->normalPath);

        //设置按钮固定尺寸
        this->setFixedSize(pix.width(),pix.height());
        //设置不规则样式
        this->setStyleSheet("QPushButton{border:0px;}");
        //设置图标
        this->setIcon(pix);
        //设置图标大小
        this->setIconSize(QSize(pix.width(),pix.height()));
    }

    //其他事件交给父类处理
    QPushButton::mouseReleaseEvent(event);
}
